package com.gl.mapper;

import com.gl.pojo.entity.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper {

    int insert(User user);

    @Select("SELECT COUNT(*) FROM user WHERE username = #{username}")
    boolean existsByUsername(String username);

    @Select("SELECT COUNT(*) FROM user WHERE email = #{email}")
    boolean existsByEmail(String email);

    @Select("SELECT username FROM user WHERE id = #{userId}")
    String selectUsernameByUserId(String userId);

    @Select("SELECT * FROM user WHERE email = #{email} AND password = #{password}")
    User selectByEmailAndPassword(String email, String password);

    @Select("SELECT * from user where id = #{userId}")
    User selectByUserId(String userId);

    List<User> page(String username);

    @Delete("DELETE from user where id = #{userId}")
    void deleteById(String userId);

    void updateUser(User user);

    @Select("SELECT email FROM user WHERE id = #{userId}")
    String selectEmailById(String userId);

    @Select("SELECT avatar_url FROM user WHERE id = #{userId}")
    String selectAvatarById(String userId);

    @Select("SELECT COUNT(*) FROM user")
    Integer count();

    @Select("SELECT COUNT(*) FROM user WHERE current_login_time BETWEEN #{start} AND #{end}")
    Integer countByTime(LocalDateTime start, LocalDateTime end);

    int updateRoleById(String userId, String role);

    String selectRoleById(String id);
}